API Documentation
Public Member Functions | List of all members
nkMemory::BufferCast< T > Class Template Reference

Holds a Buffer and make it easy to cast the binary data. More...

Public Member Functions

 BufferCast ()=default
 
 BufferCast (unsigned long long size)
 
 BufferCast (T *data, unsigned long long size)
 
 BufferCast (const Buffer &buffer)
 
 BufferCast (Buffer &&buffer)
 
 BufferCast (const BufferCast &cast)
 
 BufferCast (BufferCast &&cast)
 
 ~BufferCast ()=default
 
T * getData () const
 
unsigned long long getSize () const
 
bool empty () const
 
T & front ()
 
T & back ()
 
void clear ()
 
void resize (unsigned long long size)
 
T & append (const T &value)
 
T & operator[] (unsigned long long index)
 
const T & operator[] (unsigned long long index) const
 
 BufferCast (const std::vector< T > &vec)
 

Detailed Description

template<typename T = unsigned char>
class nkMemory::BufferCast< T >

Holds a Buffer and make it easy to cast the binary data.

This class holds a binary Buffer and abstracts all casting needed when using a buffer to keep data that can be interpreted. This buffer cast owns the buffer, meaning that it also owns the memory allocated.

If you need a simple non-owning view over the data, consider looking at BufferView.

Constructor & Destructor Documentation

◆ BufferCast() [1/8]

template<typename T = unsigned char>
nkMemory::BufferCast< T >::BufferCast ( )
default

Default constructor. The buffer will be empty.

◆ BufferCast() [2/8]

template<typename T = unsigned char>
nkMemory::BufferCast< T >::BufferCast ( unsigned long long  size)

Size constructor. Will allocate the size requested within the buffer. Memory will be 0-cleared.

Parameters
sizeThe size of the buffer to create, in number of elements.

◆ BufferCast() [3/8]

template<typename T = unsigned char>
nkMemory::BufferCast< T >::BufferCast ( T *  data,
unsigned long long  size 
)

Data constructor. Will copy the data into its internal memory.

Parameters
dataPointer to the data to copy.
sizeThe size of the data to copy, in number of elements.

◆ BufferCast() [4/8]

template<typename T = unsigned char>
nkMemory::BufferCast< T >::BufferCast ( const Buffer buffer)

Copy buffer constructor. Will duplicate the data.

Parameters
bufferThe buffer to copy.

◆ BufferCast() [5/8]

template<typename T = unsigned char>
nkMemory::BufferCast< T >::BufferCast ( Buffer &&  buffer)

Move buffer constructor. Data will be moved into the buffer being constructed.

Parameters
bufferThe buffer to move.

◆ BufferCast() [6/8]

template<typename T = unsigned char>
nkMemory::BufferCast< T >::BufferCast ( const BufferCast< T > &  cast)

Copy cast constructor. Will duplicate the data.

Parameters
castThe cast to copy.

◆ BufferCast() [7/8]

template<typename T = unsigned char>
nkMemory::BufferCast< T >::BufferCast ( BufferCast< T > &&  cast)

Move cast constructor. Data will be moved into the cast being constructed.

Parameters
castThe cast to move.

◆ ~BufferCast()

template<typename T = unsigned char>
nkMemory::BufferCast< T >::~BufferCast ( )
default

Destructor. The destructor frees the memory, invalidating all potential pointers to it.

◆ BufferCast() [8/8]

template<typename T = unsigned char>
nkMemory::BufferCast< T >::BufferCast ( const std::vector< T > &  vec)

Utility copy constructor with vectors.

Parameters
vecThe vector to copy from.

Member Function Documentation

◆ getData()

template<typename T = unsigned char>
T* nkMemory::BufferCast< T >::getData ( ) const
Returns
The pointer over the internal data.

◆ getSize()

template<typename T = unsigned char>
unsigned long long nkMemory::BufferCast< T >::getSize ( ) const
Returns
The size of the buffer, in number of elements.

◆ empty()

template<typename T = unsigned char>
bool nkMemory::BufferCast< T >::empty ( ) const
Returns
Whether the buffer is empty (true) or not (false). An empty buffer has a size of 0.

◆ front()

template<typename T = unsigned char>
T& nkMemory::BufferCast< T >::front ( )
Returns
A reference over the first element of the buffer.

◆ back()

template<typename T = unsigned char>
T& nkMemory::BufferCast< T >::back ( )
Returns
A reference over the last element of the buffer.

◆ clear()

template<typename T = unsigned char>
void nkMemory::BufferCast< T >::clear ( )

Clears the buffer, freeing its internal memory and resetting it to its empty state.

◆ resize()

template<typename T = unsigned char>
void nkMemory::BufferCast< T >::resize ( unsigned long long  size)

Resizes the buffer for it to fit a given size. This will trigger a reallocation of the data. In the process, the buffer will copy its content to the new memory area.

Parameters
sizeThe size to fit, in number of elements.

◆ append()

template<typename T = unsigned char>
T& nkMemory::BufferCast< T >::append ( const T &  value)

Appends an element to the buffer. This will cause the buffer to reallocate and copy data around. Use it wisely.

Parameters
valueThe value to append.
Returns
The reference over the element appended in the buffer.

◆ operator[]() [1/2]

template<typename T = unsigned char>
T& nkMemory::BufferCast< T >::operator[] ( unsigned long long  index)

Indexing operator.

Parameters
indexThe index of the element to index in the memory.
Returns
A reference over requested element.

◆ operator[]() [2/2]

template<typename T = unsigned char>
const T& nkMemory::BufferCast< T >::operator[] ( unsigned long long  index) const

Indexing operator, const versioned.

Parameters
indexThe index of the element to index in the memory.
Returns
A reference over requested element.

The documentation for this class was generated from the following file: